﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BLL;

namespace Web.Shalo.BanPMS1.Admin
{
    public partial class QLKhachHang : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["manv"] == null || Session["matkhau"] == null)
            {
                Response.Redirect("Default.aspx");
            }
            else
            {
                if (!IsPostBack)
                {
                    DSKhachHang();
                }
            }
        }

        public void DSKhachHang()
        {
            KhachHangController obj = new KhachHangController();
            GVKhachHang.DataSource = obj.bllDSKhachHang();
            GVKhachHang.DataBind();
        }

        protected void GVKhachHang_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GVKhachHang.PageIndex = e.NewPageIndex;
            DSKhachHang();
        }

        public void ThongBao(bool res)
        {
            if (res)
            {
                DSKhachHang();
            }
            else
            {
                Page.RegisterClientScriptBlock("mes", "<script language='javascript'>alert('Thất Bại')</script>");
            }
        }

        protected void GVKhachHang_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            bool res = false;
            KhachHangController obj = new KhachHangController();
            string makh = GVKhachHang.Rows[e.RowIndex].Cells[0].Text;
            res = obj.bllXoaKH(makh);
            ThongBao(res);
        }
    }
}